package com.zmx.job.execute.handler.b2c.order.repository;


import com.zmx.job.execute.handler.b2c.order.entity.B2COrder;
import com.zmx.job.execute.handler.common.base.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author zhaomxr
 */
public interface B2COrderRepository extends BaseRepository<B2COrder> {

    B2COrder findByOrderSn(String sn);

    @Query(value = "SELECT * FROM b2c_order WHERE order_status = 1 and payment_status = 0 and CREATE_TIME >= DATE_SUB(NOW(), INTERVAL 60 MINUTE) and CREATE_TIME < DATE_SUB(NOW(), INTERVAL 30 MINUTE)", nativeQuery = true)
    List<B2COrder> getOverdueCancelOrder();

    @Modifying
    @Query(value = "update b2c_order set order_status = ?2 where id = ?1", nativeQuery = true)
    void updateOrderStatusById(Long orderId, Integer orderStatus);
}
